﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestProject1.MainClasses;
namespace TestProject1
{
    [TestClass]
    public class TestCustomer
    {
        private IList<Customer> CustomerList = new List<Customer>();
        [TestMethod]
        public void TestMethodCustInit()
        {   // Проверка инициализации категории

            Customer c = new Customer();
            Assert.AreEqual(0, c.GetID());
            Assert.AreEqual("", c.GetName());
            Assert.AreEqual("", c.GetPriority());
            Assert.AreEqual("", c.GetContacts());
        }
        [TestMethod]
        public void TestMethodCustAdd()
        {   // Проверка добавления одной категории в список
            Customer  c = new Customer();
            CustomerList.Add(c.add(551, "Richards O.","high","contacts..."));
            Assert.IsNotNull(CustomerList.First().GetID());
            Assert.IsNotNull(CustomerList.First().GetName());
            Assert.IsNotNull(CustomerList.First().GetPriority());
            Assert.IsNotNull(CustomerList.First().GetContacts());
            Assert.IsNotNull(CustomerList.First());
        }
        [TestMethod]
        public void TestMethodCustEqualAdding()
        {   // Проверка правильного заполнения полей при добавлении категории
            Customer  c = new Customer ();
            int i = 599;
            string s1 = "Mills G.";
            string s2 = "normal";
            string s3 = "Mills' contacts...";
            CustomerList.Add(c.add(699, "Mills G.", "low", "Mills' contacts..."));
            Assert.AreNotEqual(i, CustomerList.First().GetID());
            Assert.AreEqual(s1, CustomerList.First().GetName());
            Assert.AreNotEqual(s2, CustomerList.First().GetPriority());
            Assert.AreEqual(s3, CustomerList.First().GetContacts());
        }
        [TestMethod]
        public void TestMethodCatAddingToList()
        {   // Проверка добавления нескольких категорий в список     
            Customer c = new Customer();
            CustomerList.Add(c.add(101, "customer", "high", "-"));
            Assert.IsNotNull(CustomerList.First());
            Customer c1 = new Customer();
            CustomerList.Add(c1.add(111, "customer1","normal","-"));
            Assert.IsNotNull(CustomerList.ElementAt(1));
            Customer c2 = new Customer();
            CustomerList.Add(c2.add(121, "customer2","low","-"));
            Assert.IsNotNull(CustomerList.ElementAt(2));
        }
        [TestMethod]
        public void TestMethodCustEdit()
        {
            Customer  c = new Customer();
            CustomerList.Add(c.add(199, "cust1", "very high", "-"));
            int i = 101;
            string s1 = "admin";
            string s2 = "very high";
            string s3 = "-";
            CustomerList.First().edit(i, s1,s2,s3);
            Assert.AreEqual(i, CustomerList.First().GetID());
            Assert.AreEqual(s1, CustomerList.First().GetName());
            Assert.AreEqual(s2, CustomerList.First().GetPriority());
            Assert.AreEqual(s3, CustomerList.First().GetContacts());

        }
        [TestMethod]
        public void TestMethodCustRemove()
        {   //Проверка удаления категории из списка

            Customer c1 = new Customer();
            CustomerList.Add(c1.add(103, "cust2","l","-"));
            Customer c2 = new Customer();
            CustomerList.Add(c2.add(104, "cust1","m","-"));
            Customer c3 = new Customer();
            CustomerList.Add(c3.add(105, "cust3","h","-"));
            int cnt = CustomerList.Count();

            for (int i = 0; i < CustomerList.Count(); i++)
            {
                if (CustomerList.ElementAt(i).GetName() == "cust2")
                {
                    Assert.IsNotNull(CustomerList.ElementAt(i + 1));
                    CustomerList.RemoveAt(i); cnt--;

                }
                Assert.AreEqual(cnt, CustomerList.Count());
            }
        }
    }
}
